define(function(require, exports, module) {

	var $ = require('jquery');
	var List = require('../util/list');
	require('artTemplate/artTemplate/2.0.1/template.js');
	require('jquery/jquery-form/1.0.0/jquery.form.js');
	require('jquery/jquery-json/2.4.0/jquery.json.js');
	require('seajs/seajs/2.1.1/sea.js');
	require('jbox');
	require('../util/getURL.js');
	
	require('jquery/jquery-file-upload/8.8.5/vendor/jquery.ui.widget.js');
	require('jquery/jquery-file-upload/8.8.5/jquery.iframe-transport.js');
	require('jquery/jquery-file-upload/8.8.5/jquery.fileupload.js');
	require('../util/charCount');

	exports.options = {
		listLink : '',
		listParams : '',
		pageLink : '',
		pageParams : ''
	};
	
	var pid=UrlParm.parm("pid");
	var submit_openid ;
	var uid = $("input[name=uid]").attr("value");

	//判断项目标签
	exports.tags=function(o){
		
		if($(o).val() == '0' || $(o).val() == '1'){
			$("#tags").attr({style:"display:block;"});
			$("#hot").attr({style:"display:block;"});
//			$("#needrec").attr({style:"display:block;"});
//			$("#needatt").attr({style:"display:block;"});
//			$("#needsup").attr({style:"display:block;"});
		}else {
			$("#tags").attr({style:"display:none;"});
			$("#hot").attr({style:"display:none;"});
//			$("#needrec").attr({style:"display:none;"});
//			$("#needatt").attr({style:"display:none;"});
//			$("#needsup").attr({style:"display:none;"});
		}
	
	};
	
	exports.tags("#status");
	
	$("#status").change(function(){
		$("input[type=checkbox]").attr("checked",false);
		exports.tags("#status");
		//console.log($("#status").val());
	});
	
	
	//获取修改前开放平台分类
	var getting = $.get($CONFIG.base_url + "/api/system/project/categorylist",{type:2});
	getting.done(function(data){
		$.each(data,function(key,value){
			var options = $('<option  id="'+value.id +'" name="' + value.categoryName +  '" >' + value.categoryName + '</option>');
			$("select[id=projectOpen]").append(options);
		})
		var openid = $("input[name=projectCategory]").attr("id");
		$("select[id=projectOpen]").children("option[id=" + openid +"]").attr("selected","selected");
		submit_openid = $("select[id=projectOpen]").children("option:selected").attr("id");
	});
	
	//获取修改后开放平台分类
	$("select[id=projectOpen]").change(function(){
		submit_openid = $(this).children("option:selected").attr("id");
	});
	
/*	//获取修改前项目收益分类
	var getting = $.get($CONFIG.base_url + "/api/system/project/categorylist",{type:3});
	getting.done(function(data){
		$.each(data,function(key,value){
			var options = $('<option name="tags.benefit" id="'+value.id +'" name="' + value.categoryName +  '" >' + value.categoryName + '</option>');
			$("select[id=projectBenefit]").append(options);
		})
		var benefitid = $("input[name=benefitcategory]").attr("id");
		$("select[id=projectBenefit]").children("option[id=" + benefitid +"]").attr("selected","selected");
		submit_benefitid = $("select[id=projectBenefit]").children("option:selected").attr("id");
	});
	
	//获取修改后项目收益分类
	$("select[id=projectBenefit]").change(function(){
		submit_benefitid = $(this).children("option:selected").attr("id");
	});
	
	*/
	
	//提交项目信息
	$('.add-submit').click(function(){
		var postData = form2js('update-form', '.', true);
		var tags=postData.tags;
		if(tags!=null){
			var tagstr="";
			$.each(tags, function(item){	
				tagstr=tagstr+item+",";
			});	
			postData.tags=tagstr;
		}
		var flag=0;
		$("#project-tags input[type='checkbox']").each(function(){
			if($(this).prop("checked")){
				flag=1;
			}
		});
		if(flag==0){
			postData["tags.needsup"]="null";
		}
		delete postData.projectBenefit;
		delete postData.projectOpen;
		postData["projectCategory"] ={"id": submit_openid};
		//postData["id"] = pid;
		//postData["projectBenefit"] ={"id": submit_benefitid};
		//console.log(postData);
		$.ajax({
			url : $CONFIG.base_url + "/api/preferential/update",
			type : "POST",
			data : $.toJSON(postData),
			dataType : "json",
			contentType : "application/json",
			success : function() {
				$.jBox.tip("更新活动信息成功！");
				setTimeout(function(){window.location.href=$CONFIG.base_url + '/'+$CONFIG.admin_url+'/manage/preferential/list';},1000);
			},
			error : function() {
				$.jBox.tip("更新活动信息失败！");
			}
		});
	});
});